Skip to content

feat: add updateAddon.py automated tool to complement existing - #41

Closed
abdel792 wants to merge 32 commits into
nvaccess:masterfrom
abdel792:updateAddon
Closed

abdel792 wants to merge 32 commits into
nvaccess:masterfrom
abdel792:updateAddon

Conversation

@abdel792

@abdel792 abdel792 commented Jul 9, 2026

Copy link
Copy Markdown

Link to issue number:

Close #37.

Summary of the issue:

Upgrading an existing add-on to follow the modern addonTemplate structure manually is a repetitive and error-prone process. Developers frequently encounter syntax issues or merge conflicts when manually porting old metadata into the new pyproject.toml structure.

Description of developer facing changes:

Introduces an automated update workflow. Developers can now run a single command (uv run updateAddon.py) from any directory on their PC to automatically migrate metadata, clean template placeholder data (like removing nvaccess from third-party authors lists), and merge project configurations while preserving custom formatting.

Description of development approach

  • Script implementation: Added updateAddon.py at the repository root. The script leverages an AST-aware (Abstract Syntax Tree) approach to perform safe, robust parsing and merging of TOML structures.
  • Dependency Update: Added tomlkit==0.13.0 under the # Update machinery section in pyproject.toml to support programmatic, comment-preserving TOML modifications.
  • Linter Exclusion: Added updateAddon.py to the exclude lists of both [tool.ruff] and [tool.pyright] within pyproject.toml to avoid unnecessary environmental or strict typing alerts during standard repository validation.
  • Documentation: Updated updatingExistingAddons.md to cleanly integrate prerequisites (Python 3.11+, Git available in PATH) and step-by-step instructions on how to use this new companion tool alongside the existing manual instructions.

Testing strategy:

The script and documentation workflow have been tested locally:

  1. Initialized a legacy NVDA add-on workspace using old metadata configurations.
  2. Ran git fetch template to ensure local tracking branches were up to date.
  3. Executed uv run updateAddon.py from the repository root, and verified that a _bak_ backup directory was safely generated.
  4. Checked the newly mutated pyproject.toml to ensure old custom metadata was correctly merged, template placeholder defaults were stripped, and file formatting/comments remained completely intact.
  5. Ran uv sync followed by uv run scons to ensure the final environment synchronized properly and the .nvda-addon bundle compiled successfully with zero errors.
  6. Repeated the execution from a completely different working directory outside the repository to confirm path flexibility.

Known issues with pull request:

None.


Code Review Checklist

  • Testing: Manually tested across diverse repository paths to confirm robustness. Steps to reproduce are detailed in the testing strategy.
  • API is compatible with existing add-ons: This is an infrastructure update tool for developers; it does not introduce any breaking API changes or modifications to the NVDA core ecosystem.
  • Documentation: Technical developer documentation (updatingExistingAddons.md) has been explicitly updated to reflect these changes.
  • UX of all users considered: N/A (Developer-facing infrastructure tool only).
  • Security precautions taken: N/A (The script executes locally during development and does not interact with secure screens or lock screen states).

@abdel792

abdel792 commented Jul 9, 2026

Copy link
Copy Markdown
Author

Hi @nvdaes,

I have just added you as a collaborator to this repository.

If you have some time and interest, feel free to directly review and update the docstrings in updateAddon.py to ensure they perfectly align with the project's official documentation conventions.

Thank you so much for your help and guidance on this!

@nvdaes

nvdaes commented Jul 9, 2026

Copy link
Copy Markdown

Thanks @abdel792 . I've accepted your invitation as a collaborator, and I'll try to update the docstrings.

@nvdaes

nvdaes commented Jul 9, 2026

Copy link
Copy Markdown

@abdel792 , can we add a way to ignore files which shouldn't be merged?
I think that @CyrilleB79 may be interested, and i'd like to have this possibility. For example, I don't want to use the build_addon.yml workflow since it's failing for me, and I prefer to remove it.
Also, I think that instructions for the script should be placed at the start of the file, and manual instructions maybe removed or placed at the end. BTW, they contain an error of a typo. With your permission, I'll fix it.

@abdel792

abdel792 commented Jul 9, 2026

Copy link
Copy Markdown
Author

Thanks a lot @nvdaes for your quick commits and for improving the docstrings and file headers!

Regarding your suggestions:

  1. Ignoring files: That's a great idea. Having a way to skip specific files (like workflows or custom configs) during the merge would make the tool much more flexible. I'll think about the best way to implement this (maybe via an ignore list/parameter) and update the script.
  2. Documentation structure: Completely agree. The automated tool should definitely be the primary option at the top of the file, with the manual steps as a fallback at the end. Please feel free to reorganize the file and fix the typo you found, you have my full permission!

I'll let you know once I've drafted the file-ignoring feature so we can test it. Thanks again for your amazing collaboration!

@nvdaes

nvdaes commented Jul 9, 2026

Copy link
Copy Markdown

@abdel792 , I've reorganized the documentation so that info about the script is at the start. Perhaps the information about merge should be removed=
Looking forward to see a way to ignore files/folders.
Thanks for all your amazing work.

@abdel792

abdel792 commented Jul 9, 2026

Copy link
Copy Markdown
Author

Hi @nvdaes,

Thank you so much for updating the documentation! It looks great and makes using the automated tool very clear.

Could you please do me a favor and also integrate the new feature requested by @CyrilleB79 that I just implemented in my latest commit? It allows developers to exclude specific template files during synchronization.

Here is the markdown section that needs to be added to the documentation (you can place it right before the build verification step):

### Excluding specific template files

By default, the script synchronizes every infrastructure file provided by AddonTemplate.

If you want to preserve specific files from your repository (for example, a customized GitHub workflow), you can exclude them from synchronization.

Open `updateAddon.py` and locate the `IGNORED_FILES` set near the beginning of the `main()` function:

```python
IGNORED_FILES = {
    os.path.join(".github", "workflows", "build_addon.yml").lower(),
}

Add any relative path from the template root to this set to prevent that file from being synchronized.


@abdel792

abdel792 commented Jul 9, 2026

Copy link
Copy Markdown
Author

Hi @nvdaes,

While looking closely at our documentation, I am considering a complete overhaul and restructuring of the documentation files to make everything cleaner, more cohesive, and easier to navigate for developers.

Before diving into this, I wanted to open a discussion here to get your thoughts, ideas, or any suggestions you might have regarding how we should reorganize the content.

Let me know what you think!

@abdel792

abdel792 commented Jul 9, 2026 •

Copy link
Copy Markdown
Author

I have just committed a complete overhaul and reorganization of the update documentation (updatingExistingAddons.md).

In this update, I have:

  • Restructured the document to separate the recommended automated method from the manual workflow.
  • Added the full comprehensive guide for the automated update script (updateAddon.py).
  • Added a dedicated section explaining how to exclude specific template files using the IGNORED_FILES set, as requested by @CyrilleB79.

Please let me know if you have any feedback or further suggestions.

@nvdaes, please feel free to add, modify, or correct anything you see fit—you have the green light, of course!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a developer-facing automation tool (updateAddon.py) intended to help migrate/update existing NVDA add-ons to the modern AddonTemplate structure, alongside documentation and dependency updates to support that workflow.

Changes:

  • Added updateAddon.py to clone the latest AddonTemplate, sync infrastructure files, and merge buildVars.py / pyproject.toml.
  • Updated pyproject.toml dependencies (pyright bump + new tomlkit dependency) and excluded updateAddon.py from ruff/pyright checks.
  • Expanded docs/managementFromGit/updatingExistingAddons.md with an “automated update” path plus revised manual instructions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 11 comments.

File Description
updateAddon.py New CLI tool that syncs template infrastructure and performs AST/TOML-based merges.
pyproject.toml Adds tomlkit dependency and excludes the new script from lint/type-checking; bumps pyright.
docs/managementFromGit/updatingExistingAddons.md Documents the new automated update workflow and revises the manual update steps.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread updateAddon.py Resolved
Comment thread updateAddon.py Resolved
Comment thread updateAddon.py Resolved
Comment thread updateAddon.py Resolved
Comment thread updateAddon.py Resolved
Comment thread pyproject.toml Resolved
@wmhn1872265132

Copy link
Copy Markdown

I suggest renaming updateAddon.py to updateTemplate.py to make the purpose of the file clearer.

@abdel792

Copy link
Copy Markdown
Author

Hi @wmhn1872265132,

Thanks for the suggestion! However, I'm concerned that renaming it to updateTemplate.py might be a bit misleading.

In this context, the "template" refers specifically to the upstream nvaccess/AddonTemplate repository. We aren't actually updating the template itself; rather, we are updating the local addon repository's infrastructure to align with the latest template standards.

Keeping updateAddon.py helps clarify that the target of the update is the addon's repository, not the template.

@CyrilleB79

Copy link
Copy Markdown

Hi all! You are discussing and working a lot and I'm not able to follow all this as would be needed, sorry.

It's not clear to me if this tool is needed:

  1. once for add-on X based on an old version of the template to catch up with more recent template evolution
  2. or each time that add-on X need to be updated from the template

@abdel792 you write:

Upgrading an existing add-on to follow the modern addonTemplate structure manually is a repetitive and error-prone process. Developers frequently encounter syntax issues or merge conflicts when manually porting old metadata into the new pyproject.toml structure.

Do you mean in case 1 or case 2? If you meant case 2, it's not true at all. I too have had merge difficulties to update my add-ons from template, e.g. when the structure of the buildVar.py changed. But now that my add-ons are synchronized, I update quite easily from the template. I just merge from (without --squash flag) my local templateMaster branch (which follows template/master) and usually have only conflict on the readme.md, which is easy to solve since I juste need to choose my add-on's version and discard all changes from the template on this file.

To me, upgrades from template now work correctly and I do not ask personally a new tool to perform this work, and won't probably need to use it. Sorry for the confusion.

Of course, I have a lot of commits coming from the template in my add-on's history. This may be considered undesirable by some. To me, it's not a problem. I can easily ignore them doing git log --first-parent.

Also small suggestion regarding the name: what about updateAddonFromTemplate.py?

@nvdaes

nvdaes commented Jul 10, 2026

Copy link
Copy Markdown

@CyrilleB79 wrote:

It's not clear to me if this tool is needed

Imo, it's a good addition:

  1. It avoids the necessity of add the template as a remote, which may be tricky for some people.
  2. Imagine that the template evolves and buildVars.py is replaced with something completely different, or that we want to replace .precommit.yaml with prek.toml, which seems to be easier to manage since it doesn't require to add each repo to precommit.ci. I think that this feature may manage this in a consistent way avoiding, from the start, resolving conflicts.
    I'm using it to update the template for all my add-ons now.

@CyrilleB79

Copy link
Copy Markdown

Sorry @nvdaes, I do not question the usefulness of tis tool. My question is if this tool is meant to address case 1 (first update of add-on from template), or case 2 (regular updates from template).

@nvdaes

nvdaes commented Jul 10, 2026

Copy link
Copy Markdown

@CyrilleB79 wrote:

My question is if this tool is meant to address case 1 (first update of add-on from template), or case 2 (regular updates from template).

My understanding is that this covers both cases, but I may be wrong. Let's wait for Abdel's reply.

@abdel792

Copy link
Copy Markdown
Author

Hi @CyrilleB79, thank you for sharing your thoughts! And thanks @nvdaes for jumping in with those excellent points.

To answer your question directly: as @nvdaes suspected, this tool is designed to address both cases.

  1. For Case 1 (Initial Catch-up from very old versions): In older versions of the template, addon_info was defined as a standard dictionary, and pyproject.toml didn't even exist yet. In this scenario, the script does some heavy lifting: it migrates the legacy dictionary structure in buildVars.py into the modern AddonInfo object now in use, and automatically generates a brand new, fully populated pyproject.toml file to seamlessly align the add-on with modern template standards.

  2. For Case 2 (Regular Updates / Maintenance):
    I completely understand that maintaining a templateMaster branch and doing standard git merges works smoothly for you. However, for many developers, dealing with Git remotes and tracking upstream configuration changes can be intimidating.
    Even for synchronized repositories, the script adds value by safely checking if new keys have been introduced in buildVars.py or if updates/new dependencies have been added to pyproject.toml. It merges these programmatically without triggering layout corruption or unexpected syntax conflicts. This ensures all other infrastructure components of the workspace stay perfectly aligned with the latest template evolution with a single command.

It's completely optional, of course! Your manual Git merge workflow remains fully supported and valid (and is still detailed in the documentation). This tool simply offers a streamlined alternative.

Regarding the name suggestion: updateAddonFromTemplate.py is a fantastic idea. It perfectly clarifies the script's intent without being misleading (unlike updateTemplate.py, which sounded like we were modifying the template itself). I will rename the script and update the documentation to reflect this right away!

@abdel792

Copy link
Copy Markdown
Author

Hi everyone,

I have just pushed a new update to address all the valuable feedback received from Copilot and the community:

  1. Script Renaming: Following @CyrilleB79's excellent suggestion, I have renamed the script from updateAddon.py to updateAddonFromTemplate.py. This explicitly reflects that the tool targets the local add-on repository rather than the template itself.
  2. Configuration Alignment: I've fully updated pyproject.toml to reflect this new filename, ensuring it remains excluded from ruff and pyright checks.
  3. Documentation Overhaul: The updatingExistingAddons.md documentation has been thoroughly updated to adopt the new name and incorporate Copilot's recommendations. It now accurately reflects the modern prerequisites (Python 3.13), the correct workspace path cloning sequence, and precise details about the timestamped external backup directories.

Thank you all for this amazing collaboration! I'll mark the corresponding review conversations as resolved.

@abdel792

Copy link
Copy Markdown
Author

Hi everyone,

I have just pushed a new commit to update the documentation (updatingExistingAddons.md) so that it perfectly aligns with Copilot's review and reflects the actual behavior of the script:

  1. Cloning Paths: Corrected the initial setup guide by adding the missing cd {repoName} step after cloning.
  2. Execution Modes: Explicitly documented the two execution modes of updateAddonFromTemplate.py (Standard Mode without arguments and Target Directory Mode by providing the optional addonDir argument).
  3. Python Version: Bumped the minimum required Python version to 3.13 in the docs to match the template's requirements.
  4. Backup System: Clarified that the script performs a full copy of the project into a dynamically named timestamped backup folder (<addon>_bak_<timestamp>) before editing any file.
  5. Add-on Infrastructures: Added detailed sections highlighting how the script supports both legacy dictionary-based structures (generating a fresh pyproject.toml) and modern AddonInfo-based configurations.
  6. Ignored Components: Clarified that the IGNORED_FILES set can exclude both files and entire directories.

@seanbudd: In my opinion, the PR is now in excellent shape and ready for review/merge. Please feel free to trigger a new Copilot code review cycle if you would like to verify everything.

@nvdaes, @CyrilleB79, and everyone else: please let me know if you have any additional feedback or final suggestions before we move forward!

@CyrilleB79

Copy link
Copy Markdown
   I completely understand that maintaining a `templateMaster` branch and doing standard git merges works smoothly for you. However, for many developers, dealing with Git remotes and tracking upstream configuration changes can be intimidating.
   Even for synchronized repositories, the script adds value by safely checking if new keys have been introduced in `buildVars.py` or if updates/new dependencies have been added to `pyproject.toml`. It merges these programmatically without triggering layout corruption or unexpected syntax conflicts. This ensures all other infrastructure components of the workspace stay perfectly aligned with the latest template evolution with a single command.

Yes this fully makes sense, thanks for these additional explanations. Seems that I have forgotten a bit the times when I was myself a beginner with Git and when Noelia or you were kindly answering my newbe questions!

I'll try to review your work, but not sure to be able to. So do not wait for me to go forward, i.e. for merging.

@nvdaes

nvdaes commented Jul 11, 2026

Copy link
Copy Markdown

@CyrilleB79 , I'd like to thank you, even when I'm not Abdel, for all your reviews making good questions to think about.

@abdel792

Copy link
Copy Markdown
Author

Hi @CyrilleB79,

Thank you so much! Your feedback is always incredibly valuable, and the questions you raise are exactly what helps ensure the solutions we build together are robust and cover all bases. Never apologize for asking or double-checking—it's precisely these kinds of reviews that prevent oversights and improve the workflow for everyone.

Please feel free to continue using your current manual Git merge workflow without any problem! The automated script is completely optional and just intended as an alternative helper. Both approaches (the manual workflow and the automated script) are now fully and clearly detailed in the updated documentation, so every developer can choose the method they feel most comfortable with.

No worries at all regarding the review, please take all the time you need, and don't worry if you cannot look into it right now. Thanks again for your amazing support and kindness!

@abdel792

Copy link
Copy Markdown
Author

Hi everyone,

I have just pushed a final update to the PR to address the tomlkit array layout formatting for maintainers in pyproject.toml.

@nvdaes, could you please perform the verification steps that I am going to outline in my next comment? This will help us confirm the review and validate the script's behavior together for @seanbudd.

If everything works smoothly on your end, we will be ready to ask @seanbudd for an official merge. Thank you so much!

@abdel792

Copy link
Copy Markdown
Author

Testing and Review Guide for updateAddonFromTemplate.py

Hi everyone! To help review and thoroughly test the behavior of the new updateAddonFromTemplate.py script, here is a step-by-step practical testing scenario. This test covers both a legacy migration (Case 1) and a modern configuration synchronization (Case 2).


Prerequisites & Setup

  1. Download the Test Repositories:

  2. Prepare Your Testing Workspace:

    • Create a fresh testing directory on your computer.
    • Extract both downloaded zip archives into this directory.
    • Copy your updateAddonFromTemplate.py script directly into this main testing directory.
  3. Open Your Terminal:

    • Open your command prompt (cmd or terminal).
    • Navigate to your main testing directory using the cd command.

Step 1: Testing Legacy Migration (Case 1)

In this phase, we will test how the script handles a very old add-on layout by migrating it to modern standards.

  1. Run the script targeting the legacy folder:

    python updateAddonFromTemplate.py dayOfTheWeek-legacy
  2. Verification Checklist:

    • Open dayOfTheWeek-legacy/buildVars.py: Verify that the old addon_info dictionary structure has been completely migrated into the modern AddonInfo(...) object class.
    • Check for pyproject.toml: Verify that this file (which was entirely absent) has been successfully generated at the root of the add-on folder.
    • Inspect pyproject.toml: Confirm that all legacy metadata fields—such as the add-on name, description, and maintainers—were extracted properly and populated into their correct TOML fields with proper vertical formatting.

Step 2: Testing Modern Synchronization & Key Injection (Case 2)

In this phase, we will check how the script performs maintenance updates on an already modernized repository that simply needs to catch up with recent upstream template modifications.

  1. Run the script targeting the modern folder:

    python updateAddonFromTemplate.py dayOfTheWeek-modern
  2. Verification Checklist:

    • Open dayOfTheWeek-modern/buildVars.py: Look through the file variables and verify that the missing speechDictionaries key has been safely appended without breaking any existing custom definitions.

Important Technical Note: In this second scenario, if the developer had previously customized their local pyproject.toml with specific, relaxed linting rules for pyright or ruff, those adjustments remain fully preserved! The script programmatically merges modern template dependencies, updates versions, and introduces structural alignment, but intentionally leaves the developer's custom configuration blocks completely untouched.


Advanced Testing (Optional)

For those who want to push the script further and test the newly implemented ignore features:

  • Open updateAddonFromTemplate.py and modify the IGNORED_FILES set at the beginning of the main() function to exclude a specific template file or folder (e.g., a GitHub workflow file).
  • Re-run the synchronization script on a repository and verify that your excluded files were accurately skipped during the layout synchronization phase, exactly as detailed in the technical documentation.

Thank you so much for taking the time to test and review this automation tool! Please share your findings, logs, or any feedback below.

@nvdaes

nvdaes commented Jul 12, 2026

Copy link
Copy Markdown

@abdel792 , I've following your instructions and my results are the following:

  1. Testing with dayOfTheWeek-legacy, exactly following your steps:
  • In my system, the python command is recognized as py, not python.
  • I get this error: ```import tomlkit
    ModuleNotFoundError: No module named 'tomlkit'
2. Testing dayOfTheWeek-modern

In this case, I've placed the updateAddonFromTemplate.py inside the dayOfTheWeek-modern folder. I think this is what a person using the template can expect. Then:
- I've run: `uv sync`, expecting that 'tomlkit' will then be available.
- I've run the following command: `uv run updateAddonFromTemplate.py.
The result has been the same: ModuleNotFoundError: No module named 'tomlkit'

Thanks for your great work!

@abdel792

Copy link
Copy Markdown
Author

Hi @nvdaes,

You are entirely right! Since tomlkit is a third-party library, it needs to be available in the Python environment executing the script.

To explain exactly why this happened during your tests:

  • dayOfTheWeek-legacy doesn't even have a pyproject.toml file yet, so it cannot manage modern Python dependencies.
  • dayOfTheWeek-modern does use a modern template layout, but its dependencies do not include tomlkit yet.
  • Even in the current official master branch of AddonTemplate, this dependency is not yet integrated! It is only introduced within our current Pull Request, meaning it will only become available by default after this PR is merged.

The best solution is indeed to include tomlkit in the prerequisites of the documentation, ensuring it is installed globally before running the tool.

To make it as easy as possible and let you run the script globally from anywhere right now, you can simply install (or update) tomlkit in your system's Python launcher by running this command in your terminal:

py -m pip install -U tomlkit

(Note: If someone's system uses python instead of py, they can just run python -m pip install -U tomlkit)

Could you please try running the tests again after installing tomlkit with this command?

Once that is done, your global Python environment will have the required module, and you can comfortably run the two test cases exactly as described in the guide using your standard py command!

Thank you so much for pointing this out—I'll update the prerequisites in our documentation right away!

@nvdaes

nvdaes commented Jul 12, 2026

Copy link
Copy Markdown

@abdel792, I've tested the legacy add-on now:

  1. The command which has worked for me is: py -m updateAddonFromTemplate
  2. In pyproject.toml, seems that maintainers are too much indented, with four spaces instead of two.
  3. The buildvars.py is properly migrated.
  4. In the .github/workflows folder, seems that the buildAddon.yml is not found after migration.
    Now I'll test the modern add-on.

@nvdaes

nvdaes commented Jul 12, 2026

Copy link
Copy Markdown

Tested modern add-on:

  1. buildVars.py: Contains, at the end, speechDictionaries: SpeechDictionaries = {}
  2. pyproject.toml: maintainers are perfectly indented. Note: the legacy add-on includes two maintainers, and the modern, just one.
  3. buildAddon.yml is included in the .github folder.
    Now I'll perform advanced tests in the modern add-on.

abdel792 and others added 24 commits July 28, 2026 23:29
- Rename `updateAddon.py` to `updateAddonFromTemplate.py` for clarity.
- Update `pyproject.toml` to exclude the renamed script from ruff and pyright.
- Overhaul `updatingExistingAddons.md` documentation to match the new script name and integrate Copilot's review recommendations regarding prerequisites, correct paths, and accurate backup details.
…ted pyproject.toml

Updated `mergePyprojectToml` to configure `tomlkit` with `.multiline(True)` when programmatically migrating legacy `addon_author` metadata. This ensures that authors/maintainers are generated in a clean, vertically indented structure during initial add-on template migrations, matching official repository design guidelines.
Commented out the default `build_addon.yml` path entry within the `IGNORED_FILES` set in `updateAddonFromTemplate.py`. This ensures all infrastructure components are synchronized out of the box while providing developers with a clear syntax example for excluding custom files or directories.
Updated the `mergePyprojectToml` function in `updateAddonFromTemplate.py` to ensure that when a new `pyproject.toml` is created from the template for legacy add-ons, any generated multiline arrays (such as `maintainers`) strictly use tab indentation instead of four spaces.
Restores the comprehensive function docstrings and parameter descriptions
originally written by @nvdaes, which were accidentally removed during
the recent module refactoring. All documentation is aligned with the
current module structure.
- Extract core update logic from main() into a standalone runSynchronization() function.
- Convert the positional add-on directory argument into a standard named option with short (-ad) and long (--addon-dir) flags.
- Add -td and --template-dir short/long flags to support using a local NVDA AddonTemplate folder.
- Streamline Phase 3 logic to cleanly bypass remote Git cloning when a local template directory is supplied.
- Fix a duplicate parser declaration line for the --dry-run option.
… camelCase

- Add support for custom exclusion patterns via a local `.addonmergeignore` file in the target add-on root.
- Refactor all functions, variables, and CLI arguments to strictly adhere to camelCase naming conventions.
- Standardise all docstrings to use the Sphinx documentation format (including detailed `:param:` and `:return:` fields).
- Modernise and tighten type hinting across the entire module (using Python 3.10+ native unions `|` and explicit annotations).
Create an empty `.addonmergeignore` file at the root of the repository. This template file allows developers to easily specify local file and directory exclusion patterns to prevent them from being overwritten during subsequent synchronization phases.
- Move all import statements to the module header for better code structure.
- Update the documentation to explain the .addonmergeignore procedure instead of the manual IGNORED_FILES code modification.
- Document the automated update tool CLI flags and options.
- Extract the "addon_url" metadata from buildVars.py when generating a new pyproject.toml.
- Write the "Repository" key to [project.urls], preserving empty values ("") if the URL is not set in the add-on.
- Rename the script from `updateAddonFromTemplate.py` to `syncAddonWithTemplate.py` to better reflect its synchronization purpose.
- Update ruff and pyright exclusions and tool settings in `pyproject.toml` to reference the new file name.
- Update the documentation (`updatingExistingAddons.md`) to align all text, examples, and `.addonmergeignore` instructions with the new module name.
- Standardize all documentation commands to use the safer `uv run python` syntax.
- Change `addonDir` from an optional flagged argument (`-ad`/`--addon-dir`) to a positional optional argument using `nargs="?"`.
- Allow running the script with a target directory directly (e.g., `syncAddonWithTemplate.py myAddon`) without needing the `-ad` flag.
- Preserve the default behavior (`None`/current directory) when no path argument is provided.
- Add instructions for running unit tests via pytest and uv.
- Update syncAddonWithTemplate.py usage guides to enforce the mandatory -ad option.
- Include guidelines for using uv run with the --with tomlkit flag to execute the companion tool without prior installation.
- Align script usage and testing recommendations with guidelines from @seanbudd.
…view

* Script (`syncAddonWithTemplate.py`):
  * Replace stdout prints with structured logging for file output support
  * Refactor CLI argument parsing into a dedicated helper function
  * Generate sync report in Markdown format for better readability
  * Support tomlkit mutable sequences for author/maintainer checks
  * Remove global whitespace replacements on TOML output to avoid string corruption
  * Restore strictly tab-indented author/maintainer arrays via scoped block formatting
  * Replace naive text search with ast.Name verification to detect actual `os` module usage
  * Clean up trailing EOF whitespace

* Configuration (`buildVars.py`):
  * Ensure single top-level import os insertion during AST-based merging when `os` is used

* Documentation (`updatingExistingAddons.md`):
  * Remove duplicated instruction sections and fix broken Markdown code blocks
  * Defer unit testing documentation section to PR nvaccess#42
…roups

Prevent duplicate declarations and version conflicts during uv sync by filtering
out legacy developer dependencies from project.dependencies if they are already
managed by PEP 735 dependency groups.
…ump tomlkit

- Ensure `project.dependencies` type safety during pyproject TOML merging.
- Skip `addonTemplate.egg-info` when synchronizing from a local template directory.
- Update `tomlkit` pinned version in `pyproject.toml`.
… name

Update deepMergeDicts to prevent duplicate packages with conflicting versions
when merging dependency sequences.

Introduced mergeDependencyLists to compare packages by their normalized base name
(ignoring version specifiers). This ensures existing tool versions from the template
overwrite older ones while preserving custom project dependencies.
@abdel792

Copy link
Copy Markdown
Author

Hi @seanbudd,

Just to let you know: I have rebased this branch (updateAddon) directly onto testInfraMinimal (which mirrors the changes proposed in #45).

Once #45 is merged into master, this PR (#41) will also be ready to merge cleanly with no conflicts (fast-forward merge).

Thanks!

@abdel792

abdel792 commented Aug 4, 2026

Copy link
Copy Markdown
Author

Closing this PR to create a fresh one based directly on the latest master branch, introducing the synchronization tool with the updated workflows.

@abdel792 abdel792 closed this Aug 4, 2026
seanbudd pushed a commit that referenced this pull request Nov 9, 2026
)

Replaces #41.
Summary of the issue:

While upgrading an existing add-on using standard Git commands remains fully supported, some add-on developers prefer an automated and dedicated tool to streamline the process.
Manual step-by-step migration of metadata (from buildVars.py to pyproject.toml) and file merges can require extra care and verification.
Providing an automated script offers a convenient alternative for developers who wish to perform these updates quickly and with built-in AST-based metadata handling.
Description of developer facing changes:

    Introduces the syncAddonTool package at the repository root as an automated alternative to Git-based manual upgrades for add-on developers.
    Requires tomlkit for parsing and merging pyproject.toml configurations (can be run without prior installation via uv run --no-project --with tomlkit).
    Includes a PyInstaller specification file (syncAddonTool/syncAddonTool.spec) to build a standalone executable (syncAddonTool.exe).
    Protects template-specific files, including .github/workflows/tests.yml and tests/, ensuring they are excluded from add-on synchronization.
    Excludes both syncAddonTool and the tests/ directory from static analysis in pyproject.toml (ruff and pyright).
    Adds a comprehensive verification infrastructure including both a unit test suite (tests/unit/template/test_syncAddonTool.py) and an End-to-End (E2E) CLI integration test suite (tests/e2e/template/test_syncAddonTool.py).
    Adds docs/testing.md to provide unified execution guidelines for both unit and End-to-End (E2E) tests.

Description of development approach:

    Synchronization Engine Creation: Implemented syncAddonTool using an AST-aware approach and tomlkit to seamlessly migrate legacy buildVars.py metadata or modern AddonInfo setups into pyproject.toml.
    It supports timestamped backups, custom exclusions via .addonmergeignore, and includes .github/workflows/tests.yml in PROTECTED_ELEMENTS.
    Standalone Binary Support: Added syncAddonTool/syncAddonTool.spec for building a standalone executable using uv run --with pyinstaller pyinstaller syncAddonTool/syncAddonTool.spec, eliminating external Python environment requirements for end users.
    Linter Exclusion Rules: Configured pyproject.toml to exclude syncAddonTool and tests/ from ruff and pyright checks.
    Verification & E2E Suite: Built a dual test infrastructure featuring unit tests (tests/unit/template/test_syncAddonTool.py) for internal AST/synchronization logic, and an E2E test suite (tests/e2e/template/test_syncAddonTool.py) executing isolated subprocess workflows, CLI flags, buildVars migrations, and PyInstaller binary packaging.
    Documentation Integration: Added docs/testing.md to detail CLI usage, available options, and instructions for executing both unit and E2E test suites.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add documentation for updating the template

6 participants